#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define lol long long
#define all(x) x.begin(),x.end()
#define rev(x) x.rbegin(),x.rend()
#define nline "\n"
#define hell 1000000007
#define ld long double
#define mp make_pair
#define pb push_back
#define coutyes cout << "YES" << endl
#define coutno cout << "NO" << endl
#define endl '\n'
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
const int N = 1e5+10;
vector<int>g[N];
bool vis[N];
void dfs(int vertex){
if(!vis[vertex]){
vis[vertex]=true;
for (int child: g[vertex])
{
if(!vis[child]) dfs(child);
}
}
}
void solve(){
lol n;cin>>n;
string s;cin>>s;
vector<lol>len;
lol cnt =0;
vector<lol>pos;
lol cntb =0;
for (int i = 0; i < n; ++i)
{
if(s[i]=='G'){
cnt++;
}
else{
cntb++;
if(cnt!=0){
len.pb(cnt);
pos.pb(i);
cnt=0;
}
}
}
if(cnt!=0){
len.pb(cnt);
pos.pb(n);
}
// for(auto c: len) cout<<c<<" ";
// cout<<endl;
// for(auto c: pos) cout<<c<<" ";
// cout<<endl;
if(len.size()>=3){
lol ans = 0;
for (int i = 0; i < len.size()-1; ++i)
{
if((pos[i+1]-len[i+1]-pos[i])==1){
ans=max(ans,len[i+1]+len[i]+1);
// cout<<ans<<" ";
}
}
lol r = *max_element(all(len))+1;
ans=max(ans,r);
cout<<ans<<endl;
}
else if(len.size()==2){
lol ans = *max_element(all(len))+1;
if(pos[1]-len[1]-pos[0]==1){
if(cntb==0) ans=max(ans,len[1]+len[0]-1);
else ans=max(ans,len[1]+len[0]);
// cout<<ans<<endl;
}
cout<<ans<<endl;
}
else if(len.size()==1){
cout<<len[0]<<endl;
}
else{
cout<<0<<endl;
}
}
int main(){
IOS;
int t=1;
// cin>>t;
while(t-->0){
solve();
}
return 0;
}
567B - Berland National Library | 431B - Shower Line |
282C - XOR and OR | 1582B - Luntik and Subsequences |
609A - Флеш-карты | 1207A - There Are Two Types Of Burgers |
371C - Hamburgers | 343B - Alternating Current |
758B - Blown Garland | 1681B - Card Trick |
1592A - Gamer Hemose | 493D - Vasya and Chess |
1485A - Add and Divide | 337B - Routine Problem |
1392D - Omkar and Bed Wars | 76E - Points |
762C - Two strings | 802M - April Fools' Problem (easy) |
577B - Modulo Sum | 1555B - Two Tables |
1686A - Everything Everywhere All But One | 1469B - Red and Blue |
1257B - Magic Stick | 18C - Stripe |
1203B - Equal Rectangles | 1536A - Omkar and Bad Story |
1509A - Average Height | 1506C - Double-ended Strings |
340A - The Wall | 377A - Maze |